﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ToDoBasket.Model
{
    public class Potato : NotificationObject
    {
        public Potato()
        {
            Original = "";
            IsFinished = false;
        }

        public Potato(string org)
        {
            Original = org;
            IsFinished = false;
        }
        //原始字符串
        private string original;

        public string Original
        {
            get { return original; }
            set
            {
                original = value;
                this.RaisePropertyChanged("Original");
                this.RaisePropertyChanged("Importance");
                this.RaisePropertyChanged("Prefix");
                this.RaisePropertyChanged("Description");
            }
        }

        //前缀（标签）
        public string Prefix
        {
            get
            {
                Regex regex = new Regex(@"#[^!|^#|^\s]*");
                Match match = regex.Match(original);
                return match.Value;
            }
        }

        //描述
        public string Description
        {
            get
            {
                Regex regex1 = new Regex(@"#[^!|^#|^\s]*");
                Regex regex2 = new Regex(@"[!|！]+");
                string d = regex1.Replace(original, "", 1);
                d = regex2.Replace(d, "", 1);
                return d;
            }
        }

        //重要性
        public string Importance
        {
            get
            {
                Regex regex = new Regex(@"[!|！]+");
                Match match = regex.Match(original);
                return match.Value;
            }
        }

        //是否完成
        private bool? isFinished;

        public bool? IsFinished
        {
            get { return isFinished; }
            set
            {
                isFinished = value;
                this.RaisePropertyChanged("IsFinished");
            }
        }


        //无效字符串判断
        public static bool IsValid(string original)
        {
            original = original.Trim();
            return !(original.Equals("") || original.Equals("#") || original.Equals("$"));
        }
    }
}
